<template>
    <h1>出生年份 --- {{ year }}; 年龄 --- {{ age }}</h1>

    <button @click="setYear">修改年份</button>
    <button @click="setAge">修改年龄</button>
</template>

<script>
export default {
    data() {
        return {
            year: 2005,
           
        };
    },
    methods: {
        setYear() {
            this.year = 2006
        },
        setAge() {
            this.age = 20
        }
    },
    computed: {
        age: {
            get() {
                return 2023 - this.year
            },
            set (val) {
                this.year = 2023 - val
            }
        }
    }
    
};
</script>

<style></style>
